<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('道具分配')" />
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="role-form">
				<input type="hidden" id="shopId" name="shopId" th:value="${fantasyShop.id}">
				<div class="select-list">
					<ul>
						<li>
							名称：<input type="text" name="name"/>
						</li>

						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>

		<div class="btn-group-sm" id="toolbar" role="group">
			<a class="btn btn-success" onclick="selectItem()" shiro:hasPermission="fantasy:fantasyShopItem:add">
				<i class="fa fa-plus"></i> 分配道具
			</a>
			<a class="btn btn-primary btn-edit" onclick="$.operate.edit()" shiro:hasPermission="fantasy:fantasyShopItem:edit">
				<i class="fa fa-edit"></i> 修改
			</a>
			<a class="btn btn-danger btn-del" onclick="cancelAllocItemAll()" shiro:hasPermission="fantasy:fantasyShopItem:remove">
				<i class="fa fa-remove"></i> 批量取消分配
			</a>
			<a class="btn btn-warning" onclick="closeItem()">
				<i class="fa fa-reply-all"></i> 关闭
			</a>
		</div>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true"></table>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	var editFlag = [[${@permission.hasPermi('fantasy:fantasyShopItem:edit')}]];
    var removeFlag = [[${@permission.hasPermi('fantasy:fantasyShopItem:remove')}]];
    var prefix = ctx + "fantasy/fantasyShop/allocItem";
	var shopType = [[${@dict.getType('shop_type')}]];

    $(function() {
        var options = {
            url: prefix + "/allocatedItemList",
            updateUrl: prefix + "/edit/{id}",
            queryParams: queryParams,
            sortName: "id",
            sortOrder: "desc",
            modalName: "Item",
            columns: [{
                checkbox: true
            },
			{
				field: 'id',
				title: 'ShopItem ID',
				visible: false,
			},
			{
				field: 'name',
				title: '道具名称',
				sortable: true
			},
			{
				field : 'imgsrc',
				title : '道具图片',
				sortable: true,
				formatter: showImg,
				events: 'operateEvents'
			},
			{
				field: 'itemType',
				title: '道具类型',
				sortable: true,
				formatter: function(value, row, index) {
					return $.table.selectDictLabel(shopType, value);
				}
			},
			{
				field: 'itemDesc',
				title: '道具描述'
			},
			{
				field: 'rarely',
				title: '是否稀有',
				sortable: true
			},
			{
				field: 'itemLevel',
				title: '道具等级',
				sortable: true
			},
			{
				field: 'baseQuantity',
				title: '基础数量',
				sortable: true
			},
			{
				field: 'baseSellPrice',
				title: '基础出卖价',
				sortable: true
			},
			{
				field: 'basePurchasePrice',
				title: '基础收购价',
				sortable: true
			},
			{
				field: 'curQuantity',
				title: '当前数量',
				sortable: true
			},
			{
				field: 'curSellPrice',
				title: '当前出卖价',
				sortable: true
			},
			{
				field: 'curPurchasePrice',
				title: '当前收购价',
				sortable: true
			},
			{
				field : 'createTime',
				title : '创建时间',
				sortable: true
			},
			{
				title: '操作',
				align: 'center',
				formatter: function(value, row, index) {
					var actions = [];
					actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
					actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="cancelAllocItem(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消分配</a> ');
					return actions.join('');
				}
			}]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.shopId = $("#shopId").val();
        return search;
    }

    /* 分配道具-选择道具 */
    function selectItem() {
        var url = prefix + '/selectItem/' + $("#shopId").val();
        $.modal.open("选择道具", url);
    }

    /* 分配道具-批量取消分配 */
    function cancelAllocItemAll() {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
            var data = { "shopId": $("#shopId").val(), "ids": rows.join() };
            $.operate.submit(prefix + "/cancelAll", "post", "json", data);
        });
    }

    /* 分配道具-取消分配 */
    function cancelAllocItem(id) {
        $.modal.confirm("确认要取消分配该商店吗？", function() {
            $.operate.post(prefix + "/cancel", { "shopId": $("#shopId").val(), "id": id });
        })
    }


	function showImg(value, row, index) {
		var imgSrc = ctx + 'profile/' + value;
		var s = '<a class = "view"  href="javascript:void(0)"><img style="width:30px;height:30px;"  src="'+imgSrc+'" /></a>';
		return s;
	}

	window.operateEvents = {
		'click .view': function (e, value, row, index) {
			var imgSrc = ctx + 'profile/' + value;
			layer.open({
				type: 1,
				title: false,
				closeBtn: 0,
				area: 'auto',
				skin: 'layui-layer-nobg', //没有背景色
				shadeClose: true,
				content: '<img src="'+imgSrc+'"/>'
			});
		},
	};
</script>
</body>
</html>